﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Xml;
using System.Xml.Linq;

namespace SalaryCom.Cool.Gadgets
{
    public class Seog_Jmt_ApplicationCache
    {
        private readonly Seog_Jmt_Log objLog = new Seog_Jmt_Log();
        private readonly Seog_Jmt_Data objData = new Seog_Jmt_Data();
        private readonly Seog_Jmt_XmlHelper objXmlHelper = new Seog_Jmt_XmlHelper();

        public Seog_Jmt_ApplicationCache()
        {
        }

        public void SalAddDataToCache()
        {
            if (HttpContext.Current.Application["AllHotJobTitle"] == null)
            {
                Hashtable hshAllHotJobTitle = SalAddHotJobToCache();
                HttpContext.Current.Application["AllHotJobTitle"] = hshAllHotJobTitle;
            }
        }

        private Hashtable SalAddHotJobToCache()
        {
            Hashtable hshHotJob = new Hashtable(StringComparer.OrdinalIgnoreCase);
            try
            {
                DataSet dstAllHotJobTitle = objXmlHelper.SalGetAllHotJobTitleFromXmlFile();
                if (!objData.SalIsEmptyDataSet(dstAllHotJobTitle))
                {
                    foreach (DataRow drw in dstAllHotJobTitle.Tables[0].Rows)
                    {
                        hshHotJob[drw["SEOJobKeyword"].ToString().Trim()] = drw["JobKeywordCode"].ToString().Trim();
                    }
                }
                objData.SalCleanDataSet(ref dstAllHotJobTitle);
            }
            catch (Exception ex)
            {
                objLog.SalError("SalAddHotJobToCache", ex);
            }
            finally
            {

            }
            return hshHotJob;
        }

    }
}